<template>
	<view class="vae_tab_components">
		<view class="vae_tab_box" ref="tabBox">
			<view class="vae_tab_items" ref='tabItem' v-for="(item,index) in tabList" :key="index" @click="tabsChange(index)">
				<view class="vae_tab_title" :class="index==current?'vae_tab_active':''">
					{{item.name}}
				</view>
				<uni-transition v-if="index==current" :show="true" :modeClass="mode?modeClass:modeClass2">
					<view class="under_tag"></view>
				</uni-transition>
			</view>
		</view>
	</view>
</template>

<script>
	import uniTransition from "@/components/uni-transition/uni-transition.vue"
	export default {
		props: {
			tabList: {
				type: Array,
				default: function() {
					return []
				}
			},
			current: {
				type: Number,
				default: 0,
				
			}
		},
		data() {
			return {
				modeClass:['slide-left'],
				modeClass2:['slide-right'],
				mode:1,
				leftLength:0,
			};
		},
		methods:{
			tabsChange(index){
				this.$emit('tabChange',index)
			},
		},
		watch:{
			current:function(newVal,oldVal){
				if(newVal<oldVal){
					this.mode=0;
				}else{
					this.mode=1;
				}
				// 当滑动到很右边时，tab自己滚动
				if(this.$refs.tabItem[newVal].$el.offsetLeft>330){
					this.$refs.tabBox.$el.scrollLeft=this.$refs.tabItem[newVal].$el.offsetLeft+200;
				}
			}
		},
		components: {
			uniTransition
		},
		computed:{
			abcd(){
				let leftLength=0;
				leftLength=this.$refs.tabItem[this.current].$el.offsetLeft;
				return leftLength;
			}
			
			
		},
		
	}
</script>

<style>
	.vae_tab_components {}

	.vae_tab_box {
		width: 100%;
		height: 100rpx;
		background-color: #FFFFFF;
		display: flex;
		justify-content: space-between;
		flex-wrap: nowrap;
		overflow-x: auto;
		white-space: nowrap;
		padding: 0 24rpx;
		box-sizing: border-box;
	}
	.vae_tab_box::-webkit-scrollbar{
		height: 0;
	}

	.vae_tab_items {
		height: 100%;
		margin-right: 40rpx;
		padding: 20rpx 0;
		box-sizing: border-box;
	}
	.vae_tab_items:last-child{
		margin: 0;
	}
	.vae_tab_title{
		color: #333;
		padding: 0 10rpx;
	}
	.under_tag {
		width:100%;
		background-color: pink;
		height: 4rpx;
		margin-top: 20rpx;
	}
	
</style>
